//------------------------------ CONFIG

_unit = _this select 0;
_type = typeOf _unit;
_owner = _unit getVariable ["owner", nil];
_adminVehicles = [GHOSTHAWK, HUMMINGBIRD];
_lifthelis = ["I_Heli_Transport_02_F","I_Heli_light_03_unarmed_F","B_Heli_Transport_01_camo_F","B_Heli_Transport_01_F","B_Heli_Light_01_F","B_Heli_Light_01_F"];
_ghosthawk = ["B_Heli_Transport_01_camo_F","B_Heli_Transport_01_F"];
_strider = ["I_MRAP_03_F","I_MRAP_03_hmg_F","I_MRAP_03_gmg_F"];
_hummingbird = ["B_Heli_Light_01_F","B_Heli_Light_01_armed_F"];
_arsenal = ["B_Truck_01_ammo_F","B_Truck_01_covered_F","B_Truck_01_box_F"];

//------------------------------ INITIALIZE VEHICLES

if (isNull _unit) exitWith {};

//No firing in base
_unit addeventhandler ["fired",{  if (vehicle (_this select 0) in list base ) then {deleteVehicle (_this select 6)};}];

//Editable by Zeus
{_x addCuratorEditableObjects [[_unit],true];} forEach allCurators;

//Clear vehicle cargo
if (isServer) then {
	clearItemCargoGlobal _unit;
	clearWeaponCargoGlobal _unit; 
	clearMagazineCargoGlobal _unit;
};

if (_unit isKindOf "Helicopter") then {
	_unit enableCoPilot false;
	if (_type in _lifthelis) then {
		[_unit] execVM "scripts\vehicle\sling\sling_setupUnit.sqf"
	};
	if (_type in _ghosthawk) then {
		_unit removeMagazinesTurret ["2000Rnd_65x39_Belt_Tracer_Red",[1]];	//Remove ammo from side gunners
		_unit removeMagazinesTurret ["2000Rnd_65x39_Belt_Tracer_Red",[2]];	//Remove ammo from side gunners
		//_unit lockturret [[0],true];	//Lock CoPilot
		_unit lockturret [[1],true];	//Lock Left Gunner
		_unit lockturret [[2],true];	//Lock Right Gunner
		_unit addAction ["<t color='#0000f6'>Ammo Drop</t>", "scripts\vehicle\drop\drop.sqf",[1],0,false,true,"","driver _target == _this"];
		[_unit] execVM "scripts\vehicle\animate\ghosthawk.sqf";
	};
	if (_type in _hummingbird) then {
		if (_unit in _adminVehicles) then {
			_unit setObjectTexture [0,"a3\air_f\Heli_Light_01\Data\Skins\heli_light_01_ext_wasp_co.paa"];
		} else {
			_unit setObjectTexture [0,"a3\air_f\Heli_Light_01\Data\heli_light_01_ext_ion_co.paa"];
		};
	};
	if (!(_unit in _adminVehicles) AND (isServer) AND (isNil "_owner")) then {
		_unit addEventHandler ["getIn", {
			private ["_player", "_uid", "_position"];
			_player = _this select 2;
			_uid = getPlayerUID _player;
			_position = _this select 1;
			if (!(_player isKindOf "B_Helipilot_F") AND !(_uid in Evo_Admins) AND (_position == "driver") AND (PARAMS_PilotsOnly == 1)) then {
				[[_player, false],"SXP_fnc_getOut", _player] spawn BIS_fnc_MP;
			};
		}];
	};
};
if (_unit isKindOf "Plane") then {
	[_unit] execVM "scripts\vehicle\airplane\planeActions_init.sqf";
};
if (_unit isKindOf "LandVehicle") then {
	if (_type in _strider) then {
		_unit setObjectTexture [0,'\A3\soft_f_beta\mrap_03\data\mrap_03_ext_co.paa'];
		_unit setObjectTexture [1,'\A3\data_f\vehicles\turret_co.paa']; 
	};
};
if (_type in _arsenal) then {
		[_unit] execVM "scripts\arsenal\openArsenal.sqf";
};

if (!isNil "_owner") then {
	_unit addAction ["<t color='#ff1111'>Return Vehicle</t>", "scripts\veh_store\return.sqf",[],91,false,true,"",
	"(driver _target == _this) && speed _target < 4 && speed _target > -4 && getPos _target select 2 < 1 && ((_target in (list vehiclestore1)) || (_target in (list vehicleStore2)))"];
};

if (_unit in _adminVehicles) then {
	_unit allowdamage false;
	[_unit] execVM "scripts\arsenal\openArsenal.sqf";
	if (isServer) then {
		_unit addEventHandler ["getIn", {
			private ["_player", "_uid", "_position"];
			_player = _this select 2;
			_uid = getPlayerUID _player;
			_position = _this select 1;
			if (!(_uid in Evo_Admins) AND (_position == "driver")) then {
				[[_player, true],"SXP_fnc_getOut", _player] spawn BIS_fnc_MP;
			};
		}];
	};
};